package com.artisan.domain.repository;

import com.artisan.domain.dto.AccountDto;
import com.artisan.domain.entity.MAccount;
import com.artisan.domain.entity.QMAccount;
import com.artisan.domain.entity.QMRole;
import com.artisan.domain.repositoryInterface.IAccountRepository;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AccountRepository {
    @Autowired
    private JPAQueryFactory jpaQueryFactory;

    public JPAQuery<Tuple> find(Predicate predicate) {
        QMAccount account = QMAccount.mAccount;
        QMRole role = QMRole.mRole;

        JPAQuery<Tuple> result = jpaQueryFactory.select(account, role).from(account).leftJoin(role).on(account.roleId.eq(role.id)).where(predicate);
        return result;
    }
}
